﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using app_common;
using System.Collections;
using tpos_custom_control;
using tpos_business;

namespace tpos_front_end
{
    public partial class frm_front_end_order : Form
    {        
        clsOrder clsB = new clsOrder();
        string tableCode = "";
        DataTable DTITEMS = new DataTable();
        string ITEMSELECTED = "";
        string orderCode = "";

        public frm_front_end_order(string _tableCode)
        {
            InitializeComponent();
            tableCode = _tableCode;
        }

        private void btn_order_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            APP_FORM.frm_current.Close();
            APP_FORM.frm_parent.Show();            
        }

        private void frm_front_end_order_Load(object sender, EventArgs e)
        {
            //Check if table ordered.
            //--Show bill

            //--Search Table Name.

            //--Get item list
            DTITEMS = clsB.getItem();
            showItem();



        }

        private void showItem()
        {
            try
            {
                if (DTITEMS != null)
                {
                    dataGridItems.DataSource = DTITEMS;
                }
            }
            catch { }
        }

        private void txtTimkiem_Leave(object sender, EventArgs e)
        {
            txtTimkiem.Text = "Tìm kiếm";
        }

        private void txtTimkiem_Enter(object sender, EventArgs e)
        {
            txtTimkiem.Text = "";
        }

        private void txtTimkiem_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (this.ActiveControl == txtTimkiem)
                {
                    if (txtTimkiem.Text.Trim() != "Tìm kiếm")
                    {                        
                        DTITEMS = clsB.getItemByCodeName(txtTimkiem.Text);
                        dataGridItems.DataSource = DTITEMS;
                    }
                }
            }
            catch { }
        }

        private void dataGridItems_CurrentCellChanged(object sender, EventArgs e)
        {
            try
            {
                ITEMSELECTED = DTITEMS.Rows[dataGridItems.CurrentCell.RowIndex][0].ToString();
            }
            catch { ITEMSELECTED = ""; }
        }

        private void btnAddItem_Click(object sender, EventArgs e)
        {
            if (ITEMSELECTED != "")
            {
                frm_front_end_order_cf_qty f = new frm_front_end_order_cf_qty("ABC", "XYZ");
                f.ShowDialog();
                int qty = f.qty;
                if (qty > 0)
                {
                    if (orderCode != "")
                    {
                        //Insert New Item
                    }
                    else//New item
                    {
                        //Insert New Bill
                    }
                }
            }
            else
            {
                MessageBox.Show("Vui lòng chọn mặt hàng bán.", STATUS_MESSAGE.CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

       
    }
}
